home *** CD-ROM | disk | FTP | other *** search
/ Greenhouse Effect Detection Expriment / NASA Greenhouse Effect Detection Expriment 1992 - Disc 2.iso / software / dos / cdf22pc / src / tools / cdflist1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-11  |  59.8 KB  |  2,227 lines

  1. /******************************************************************************
  2. *
  3. *  NSSDC/CDF                        CDFlist.  Part 1 of 2.
  4. *
  5. *  Version 2.0, 9-Mar-92, ST Systems (STX)
  6. *
  7. *  Modification history:
  8. *
  9. *   V1.0  29-Jan-91, H Leckner    Original version (for CDF V2.0).
  10. *   V1.1   5-Feb-91, J Love    Modified error handling.
  11. *   V1.2  12-Feb-91, H Leckner    Fixed variable name handling.
  12. *   V1.3  13-Mar-91, H Leckner    Fixed attribute entry problem.
  13. *   V1.4  20-Mar-91, H Leckner    Fixed problem with large dimension sizes.
  14. *   V1.5  26-Mar-91, J Love    Cast malloc calls to proper type.  Fix for
  15. *                possible char array overwrite.
  16. *   V1.6   4-Apr-91, H Leckner    Fixed problem with filtering REAL8 values.
  17. *   V1.7   5-Jun-91, S Sudarsan Enhanced file/directory input handling  
  18. *                               along with file_names.c.  Changed logical
  19. *                name for HELP directory.
  20. *   V1.8  25-Jun-91, J Love    Added QOP.  Added CDF_EPOCH as a data type.
  21. *             H Leckner    Added #include <sys/types.h>.
  22. *   V1.9  12-Jul-91, J Love    TRUE/FALSE.  Changed for Cray/UNICOS port.
  23. *             H Leckner    Added use of VALIDMIN/VALIDMAX for initial
  24. *                filters (if NSSDC_STANDARD).  Use 'Exit' &
  25. *                'ExitBAD'.
  26. *   V1.10 20-Sep-91, H Leckner    Fixed window labeling.  Modified for IBM-PC
  27. *             J Love    port.
  28. *   V1.11 11-Oct-91, H Leckner    Added ability to select more than 8
  29. *                variables.
  30. *   V1.12 18-Oct-91, H Leckner  Changed for IBM-RS6000 port.
  31. *   V2.0   9-Mar-92, H Leckner    IBM PC port.  CDF V2.2.
  32. *
  33. ******************************************************************************/
  34.  
  35. #include <stdio.h>
  36. #include <math.h>
  37. #include <string.h>
  38. #if defined (vms)
  39. #include <descrip.h>
  40. #endif
  41. #if defined(__MSDOS__)
  42. #include <dos.h>
  43. int      _Cdecl kbhit( void );
  44. #endif
  45.  
  46. #define CDFLIST 1
  47. #include "cdfdist.h"
  48. #include "wfl.h"
  49. #include "kb_def.h"
  50. #include "utility.h"
  51. #include "cdflist.h"
  52.  
  53. #if NSSDC_STANDARD
  54. Boolean    initialfilters = TRUE;
  55. #else
  56. Boolean initialfilters = FALSE;
  57. #endif
  58. Boolean check_epoch(str, scale)
  59. char        str[];
  60. double        *scale;
  61. {
  62. static char    default_time[] = " 00:00:00.000";
  63. long int    len;
  64. long int    rcode;
  65. *scale = 0.;
  66. len = strlen(str);
  67. if(len == 0)
  68.    return(TRUE);
  69. else if(len < 11)
  70.     return(FALSE);
  71. else if(len < 24)
  72.     strcat(str, default_time+(len+2-13));
  73. rcode = epochParse(str, &ep);
  74. *scale = ep.tSince0;
  75. return(rcode);
  76. }
  77.  
  78.  
  79. int precision(num)
  80. double        num;
  81. {
  82. double        abs_value;
  83. int    p;
  84. abs_value = fabs(num);
  85. if(abs_value < 1.)
  86.     p = 5;
  87. else if(abs_value < 10.)
  88.     p = 4;
  89. else if(abs_value < 10000.)
  90.     p = 3;
  91. else if(abs_value < 100000.)
  92.     p = 2;
  93. else
  94.     p = 1;
  95. return(p);
  96. }
  97. int CDFLIST_CDF_name(screen, CDF, field_num, input_type)
  98. struct    GLOBAL_struct    *screen;
  99. struct    CDF_struct    *CDF;
  100. long int        *field_num;
  101. long int        *input_type;
  102. {
  103. char            file_spec[256],temp[256];
  104. static char        save[CDF_PATHNAME_LEN];
  105. char            save_name[CDF_PATHNAME_LEN];
  106. char            save_temp[CDF_PATHNAME_LEN];
  107. char             **directory_list;
  108. char            **result_spec_list;
  109. int            num_files = 0;
  110. int            termcode, i, row;
  111. int            drows;
  112. long int        CDF_num;
  113. int            tcode;
  114. int            done;
  115. int             dir;
  116. static int        first = TRUE;
  117. char            row_data[CDF_COLUMNS];
  118. #if defined(unix)
  119. static char curr_dir[] = "./*.cdf" ;
  120. #else
  121. #if defined(__MSDOS__)
  122. static char curr_dir[] = ".\\*.cdf";
  123. #else
  124. #if defined(vms)
  125. static char curr_dir[] = "[]*.cdf";
  126. #endif
  127. #endif
  128. #endif
  129.  
  130. static char dir_mes[] =
  131. "Enter Directory and/or CDF name (default=CDFs in current directory)";
  132. static char dir_error[] = "No CDFs found, reenter directory and/or CDF name";
  133. static char select_mes[] =
  134. "Select a CDF or press Q to enter a new Directory/CDF_name";
  135. struct vid_struct      *DIR_display;
  136. char            key_line1[KEY_COLUMNS-COL_OFFSET+1];    /* V1.5 */
  137. char                   key_line2[KEY_COLUMNS-COL_OFFSET+1];    /* V1.5 */
  138. int            new_CDF;
  139. int             regfile;
  140. int            last_error = FALSE;
  141. strcpy(save_name, C.CDF_name);
  142. new_CDF= FALSE;
  143. done = FALSE;
  144. regfile = FALSE;
  145. while(!done)
  146. {
  147. if(*input_type == MANUAL)
  148.    {
  149.    if(first)
  150.       {
  151.       key_line1[0] = '\0'; key_line2[0] = '\0';
  152.       strcat(key_line1, CNTRLM); strcat(key_line1, RET);strcat(key_line1, CNTRLN);
  153.       strcat(key_line2, CNTRLW);strcat(key_line2, HLP);strcat(key_line2, CNTRLD);        /* V1.5 */
  154.       CDFLIST_load_keydef(S.KEY_vid, key_line1, key_line2);
  155.       if(!last_error)
  156.      {
  157.      for (i=0; i < CDF_NAME_LENGTH; i++)
  158.           C.CDF_name[i] = '\0';
  159.      strcpy(C.CDF_name, default_name);
  160.  
  161.      CDFLIST_put_selection(S.CDF_vid, CDF_display, 0,
  162.           C.CDF_name, CDF_NAME_LENGTH-COL_OFFSET, REVERSE);
  163.      }
  164.       CDFLIST_put_message(S.MES_vid, dir_mes, NOBELL, NORMAL, NOPAUSE);
  165.       input_field(S.CDF_vid, C.CDF_name,
  166.       CDF_NAME_ROW, CDF_NAME_COL, CDF_NAME_LENGTH-COL_OFFSET, &termcode);
  167.       }
  168.    else
  169.       CDFLIST_put_selection(S.CDF_vid, CDF_display, 0,
  170.           save, CDF_NAME_LENGTH-COL_OFFSET, REVERSE);
  171.    }
  172. else
  173.     termcode = KB_RETURN;
  174. *input_type = MANUAL;
  175. first = FALSE;
  176. last_error = FALSE;
  177. CDFLIST_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS-COL_OFFSET);
  178. if(termcode == KB_CTRL_F)
  179.    {
  180.    CDFLIST_field_menu(screen, field_num);
  181.    if((int) (*field_num) != CDF_FIELD)
  182.       {
  183.       done = TRUE;
  184.       tcode = QUIT;
  185.       }
  186.    else
  187.       first = TRUE;
  188.    }
  189. else
  190.    {
  191.    row = CDF_NAME_ROW;
  192.  
  193.    read_display(S.CDF_vid, row, row_data);
  194.  
  195.    for (i=CDF_NAME_COL; i < CDF_NAME_COL+CDF_NAME_LENGTH-1; i++)
  196.     if(row_data[i-1] != 32)
  197.        temp[i-CDF_NAME_COL] = row_data[i-1];
  198.     else
  199.        temp[i-CDF_NAME_COL] = '\0';
  200. /*
  201. Save for next time
  202. */
  203.    strcpy(save_temp, temp);
  204.  
  205.    strcpy(file_spec, temp);
  206.    if(strlen(file_spec) == 0)
  207.       strcpy(file_spec, curr_dir);
  208.    else
  209.       {
  210.       dir = FALSE;
  211.       strcpy(temp, file_spec);
  212.       strcat(temp,".cdf");
  213.       if(!IsReg(temp))
  214.       {
  215.       regfile = FALSE;
  216.       if(IsDir(file_spec))
  217.           {
  218.           AppendToDir(file_spec, "*.cdf");
  219.           dir = TRUE;
  220.           }
  221.       else
  222.           strcat(file_spec, ".cdf");
  223.       }/* end else */
  224.       else
  225.       {
  226.       regfile = TRUE;
  227.       strcat(file_spec, ".cdf");
  228.       }
  229.       }/* end else */
  230.    num_files = DirList(file_spec, &directory_list, &result_spec_list);
  231.    if(num_files > 0)
  232.       {
  233.       strcpy(save, save_temp);
  234.       RemoveExtensions(num_files, result_spec_list);
  235.       done = TRUE;
  236.       if(num_files == 1 && regfile)
  237.      {
  238.      CDF_num = 1;
  239.      tcode = KB_RETURN;
  240.      first = TRUE;
  241.      }
  242.        else
  243.      {
  244. /*
  245. allocate the space for a vid structure which contains the CDF NAMES
  246. */
  247.      DIR_display = (struct vid_struct *)
  248.            malloc(num_files * sizeof(struct vid_struct));
  249.      if(DIR_display == NULL)return(BAD_MALLOC);
  250. /*
  251. Load in the cdf names into the structure
  252. */
  253.      for (i=0; i<num_files; i++)
  254.        {
  255.        DIR_display[i].row = 1;
  256.        DIR_display[i].col = 1;
  257.        strcpy(DIR_display[i].label, result_spec_list[i]);
  258.        DIR_display[i].field_col = 1;
  259.        }
  260.      if((num_files+ROW_OFFSET) > DIR_ROWS)
  261.          drows = DIR_ROWS;
  262.      else
  263.          drows = num_files + ROW_OFFSET;
  264. #if defined(vms)
  265.      change_virtual_display(drows, DIR_COLUMNS, S.DIR_vid,
  266.                   BORDER, BOLD);
  267. #else
  268.      change_virtual_display(drows, DIR_COLUMNS, &S.DIR_vid,
  269.                   BORDER, BOLD);
  270. #endif
  271.      CDFLIST_put_message(S.MES_vid, select_mes, NOBELL, NORMAL, NOPAUSE);
  272.      CDFLIST_menu_keydef(screen);
  273.      CDFLIST_select_menu_item(S.DIR_vid,
  274.        S.MES_vid, &CDF_num, DIR_display, num_files, drows,
  275.        DIR_COLUMNS, DIR_ROW_PASTE, DIR_COL_PASTE, MENU, &tcode);
  276.      free (DIR_display);
  277.      } /* end num_files > 1 */
  278.      if(tcode == KB_RETURN)
  279.           {
  280.           if(dir || strlen(directory_list[CDF_num-1]) > 0)
  281.          {
  282.          strcpy(C.CDF_name, directory_list[CDF_num-1]);
  283.          AppendToDir(C.CDF_name, result_spec_list[CDF_num-1]);
  284.          }
  285.           else
  286.          strcpy(C.CDF_name, result_spec_list[CDF_num-1]);
  287.  
  288.           C.CDF_name[CDF_NAME_LENGTH]= '\0';
  289.           CDFLIST_put_selection(S.CDF_vid, CDF_display, 0,
  290.           C.CDF_name, CDF_NAME_LENGTH-COL_OFFSET, REVERSE);
  291.           new_CDF = TRUE;
  292.           (*field_num)++;
  293.           }
  294.        else
  295.           {
  296.           change_rendition(S.CDF_vid, CDF_NAME_ROW, CDF_NAME_COL, 1,
  297.           strlen(C.CDF_name), REVERSE);
  298.           if(tcode == KB_CTRL_F)
  299.          {
  300.          CDFLIST_field_menu(screen, field_num);
  301.          if((int) (*field_num) == CDF_FIELD)done = FALSE;
  302.          }
  303.           else
  304.          done = FALSE;
  305.           first = TRUE;
  306.       } /* num > 1 */
  307.  
  308.       free (directory_list);
  309.       free (result_spec_list);
  310.        } /*num_file > 0*/
  311.        else
  312.        {
  313.        CDFLIST_put_message(S.MES_vid, dir_error, RINGBELL, NORMAL, PAUSE);
  314.        first = TRUE;
  315.        last_error = TRUE;
  316.        }
  317.    }/*keyboard != C-F*/
  318. }/*done?*/
  319. /*
  320. If a new CDF was not selected put the old one back on the input line
  321. */
  322. if(!new_CDF)
  323.    {
  324.    strcpy(C.CDF_name, save_name);
  325.    CDFLIST_put_selection(S.CDF_vid, CDF_display, 0,
  326.           C.CDF_name, CDF_NAME_LENGTH-COL_OFFSET, REVERSE);
  327.    }
  328. return(tcode);
  329.  
  330. }
  331. #ifdef vms
  332. void CDFLIST_save_screen(screen)
  333. struct    GLOBAL_struct    *screen;
  334. {
  335. save_screen(&S.save_id);
  336. }
  337. void CDFLIST_restore_screen(screen)
  338. struct    GLOBAL_struct    *screen;
  339. {
  340. restore_screen(S.save_id);
  341. }
  342. #endif
  343. long int    get_var_num(possible, mnemonic, num_poss)
  344. struct variable_struct    possible[];
  345. char            *mnemonic;
  346. long int        num_poss;
  347. {
  348. long int        i;
  349. long int        var_num;
  350. long int        size;
  351. var_num = NOTTHERE;
  352. for(i=0; i<num_poss && var_num == NOTTHERE; i++)
  353.     {
  354.     if(possible[i].var_mnemonic_len > CDFLIST_MAX_VAR_LENGTH)
  355.        size = CDFLIST_MAX_VAR_LENGTH;
  356.     else
  357.        size = possible[i].var_mnemonic_len;
  358.     if(strncmp(possible[i].var_mnemonic, mnemonic, size) == 0) var_num = i;
  359.     }
  360. return(var_num);
  361. }
  362.  
  363. long int    get_1char(prompt)
  364. char        prompt[];
  365. {
  366. long int    resp;
  367. #if defined (vms)
  368. printf(prompt);
  369. resp = getchar();
  370. fflush(stdin);
  371. printf("\n");
  372. #else
  373. #if defined (ultrix)
  374. wprintw(stdscr, "%s",prompt);
  375. wrefresh(stdscr);
  376. fflush(stdin);
  377. resp = getchar();
  378. fflush(stdin);
  379. wrefresh(stdscr);
  380. #else
  381. #if defined(unix) | defined(__MSDOS__)
  382. wprintw(stdscr, "%s",prompt);
  383. wrefresh(stdscr);
  384. resp = getchar();
  385. fflush(stdin);
  386. #endif
  387. #endif
  388. #endif
  389.  
  390. return(resp);
  391. }
  392.  
  393. #if defined(vms)
  394. main (argc, argv)
  395. #else
  396. void main (argc, argv)
  397. #endif
  398. int        argc;
  399. char        *argv[];
  400. {
  401. static struct    CDF_struct CDF;
  402. static struct    GLOBAL_struct    screen;
  403. struct        variable_struct *variables;
  404. struct        variable_struct *select;
  405. struct        vid_struct    *SELECT_display;
  406. struct        vid_struct    *VAR_display;
  407. union         mixed        *data_values;
  408. CDFstatus    rcode;
  409. long int    i;
  410. int        var_rows;
  411. int        var_columns;
  412. long int    num_select;
  413. long int    num_filter;
  414. int        CDF_is_OPEN = FALSE;
  415. static char    open_mes[] = "Opening CDF...";
  416. /* static char    open_error[] = "CDFLIST_open: Error opening or Reading CDF";*/
  417. static char    novar_mes[] = "No variables selected for listing";
  418. static char    MULT_mes[] =
  419. "Must use default min/max values (EPOCH OK) for this CDF when creating new CDF";
  420. long int    mult_flag;
  421. FILE        *fptr;
  422. long int    field_num;
  423. long int    exit_code;
  424. long int    tcode;
  425. long int    num = 8;
  426. long int    cdf_input = MANUAL;
  427. #if defined(unix) || defined(__MSDOS__)
  428. char *getenv();
  429. char *s;
  430. #endif
  431. char        temp[CDF_PATHNAME_LEN];
  432. char        help_file_name[80];
  433.  
  434. QOP *qop;
  435. static char *validQuals[] = { NULL };
  436.  
  437. for (i=0; i < CDF_NAME_LENGTH; i++) CDF.CDF_name[i] = '\0';
  438.  
  439. qop = Qop (argc, argv, validQuals, NULL);
  440. if (qop == NULL) ExitBAD;
  441. switch (qop->Nparms) {
  442.   case 0:
  443.      strcpy(CDF.CDF_name, default_name);
  444.   break;
  445.   case 1:
  446.       cdf_input = AUTO;
  447.       strcpy(CDF.CDF_name, qop->parms[0]);
  448.       strcpy(temp, qop->parms[0]);
  449.       strcat(temp,".cdf");
  450.       if(!IsReg(temp))cdf_input = DIRECTORY;
  451.   break;
  452.   default:
  453.     printf ("Too many parameters.\n");
  454.     ExitBAD;
  455. }
  456. #if defined(unix)
  457. s = getenv("CDF_HELP");
  458. if(s)
  459.   {
  460.   strcpy(help_file_name, s);
  461.   strcat(help_file_name, "/cdflist.hlp");
  462.   }
  463. else
  464.   strcpy(help_file_name, "../help/cdflist.hlp");
  465. HELP_ptr = fopen(help_file_name, "r");
  466. #endif
  467. #ifdef vms
  468. strcpy(help_file_name,"CDF$HELP:cdflist.hlp");
  469. HELP_ptr = fopen(help_file_name, "r");
  470. #endif
  471. #if defined(__MSDOS__)
  472. s = getenv("CDF_HELP");
  473. if(s)
  474.   {
  475.   strcpy(help_file_name, s);
  476.   strcat(help_file_name, "\\cdflist.hlp");
  477.   }
  478. else
  479.   strcpy(help_file_name, ".\\cdflist.hlp");
  480. HELP_ptr = fopen(help_file_name, "r");   
  481. if(HELP_ptr == NULL)
  482.   {
  483.   strcpy(help_file_name,"c:\\cdf22\\help\\cdflist.hlp");
  484.   HELP_ptr = fopen(help_file_name, "r");   
  485.   }
  486. #endif
  487.  
  488.  
  489. variables = NULL;
  490. select = NULL;
  491. VAR_display = NULL;
  492. SELECT_display = NULL;
  493. data_values = NULL;
  494.  
  495. field_num = CDF_FIELD;
  496. CDF.file_name[0] = '\0';
  497. CDF.output = TERMIN;
  498. num_select = 0;
  499. SO.EPOCH_format = EPOCHFORM_DEF;
  500. SO.EPOCH_output_len[0] = 25;
  501. SO.EPOCH_output_len[1] = 17;
  502.  
  503. init_var_display(init_display, num);
  504. CDFLIST_open_screen(&screen);
  505.  
  506. while(field_num != EXIT)
  507.  {
  508.  switch (field_num)
  509.       {
  510.       case CDF_FIELD:
  511.        CDFLIST_put_selection(screen.CDF_vid, CDF_display,
  512.        CDFNAME_ELEMENT_NUM-1, CDF.CDF_name, CDF_NAME_LENGTH-COL_OFFSET,
  513.                  REVERSE);
  514.        if(cdf_input != AUTO)
  515.           tcode = CDFLIST_CDF_name(&screen, &CDF, &field_num, &cdf_input);
  516.        else
  517.           {
  518.           field_num = OUT_FIELD;
  519.           tcode = CONTINUE;
  520.           }
  521.        if(tcode != QUIT && field_num != EXIT && strlen(CDF.CDF_name) > 0)
  522.           {
  523.           if(CDF_is_OPEN)
  524.          {
  525.          free(variables);
  526.          free(select);
  527.          free(VAR_display);
  528.          free(SELECT_display);
  529.          free(data_values);
  530.          if (CDF.num_attrs > 0) free(CDF.attr);
  531.          rcode=CDFLIST_close(&CDF);
  532.          }
  533.           CDFLIST_put_message(screen.MES_vid, open_mes, NOBELL, BLINK,
  534.         NOPAUSE);
  535.           rcode = CDFLIST_open(&CDF, &variables, &select, &VAR_display,
  536.             &SELECT_display, &data_values);
  537.           cdf_input = MANUAL;
  538.           if(rcode < CDF_OK)                /* V1.1 */
  539.             {
  540.             exit_code = print_error(&screen, rcode);
  541.             /* CDFLIST_put_message(screen.MES_vid, open_error, RINGBELL,
  542.                      NORMAL, PAUSE);*/
  543.             if(exit_code == NOCONTINUE)field_num = CDF_FIELD;
  544.             CDF_is_OPEN = FALSE;
  545.             }
  546.           else
  547.             {
  548.             CDF_is_OPEN = TRUE;
  549.             num_select = 0;
  550.             CDFLIST_var_menus(&screen, &CDF, &var_rows, &var_columns);
  551.             CDFLIST_CDF_info(&screen, &CDF, CDF_display, OUT_display);
  552.             CDFLIST_clear_row(screen.VAR_vid, init_display, 4,
  553.             VAR_NUM_ELEMENTS, VAR_COLUMNS-COL_OFFSET);
  554.             CDFLIST_clear_row(screen.MES_vid, MES_display, 1, 1,
  555.             MES_COLUMNS-COL_OFFSET);
  556.             init_var_display(VAR_display, CDF.num_vars);
  557.             load_vid(screen.VAR_vid, VAR_display, 0,
  558.                 VAR_NUM_ELEMENTS, VAR_label);
  559.             }
  560.           }
  561.        break;
  562.       case OUT_FIELD:
  563.        CDFLIST_output(&screen, &CDF, &fptr, &field_num);
  564.        CDFLIST_clear_row(screen.MES_vid, MES_display, 1, 1,
  565.        MES_COLUMNS-COL_OFFSET);
  566.        break;
  567.       case VAR_FIELD:
  568.        CDFLIST_select_VAR(&screen, var_rows, var_columns, VAR_display,
  569.         SELECT_display, variables, CDF.num_vars, select,
  570.         &num_select, &field_num);
  571.        break;
  572.       case HELP_FIELD:
  573.        CDFLIST_help(&screen);
  574.        CDFLIST_field_menu(&screen, &field_num);
  575.       case LIST_DATA:
  576.        if(num_select == 0)
  577.           CDFLIST_put_message(screen.MES_vid, novar_mes, RINGBELL, NORMAL,
  578.                     NOPAUSE);
  579.        else
  580.           {
  581.           num_filter = num_select;
  582. /*
  583. if output is to a CDF add the independent variables that were not selected
  584. to the selected ones.
  585. */
  586.           if(CDF.output == CDFOUT)
  587.          {
  588.          CDFLIST_check_filters(select, num_select,
  589.             select, CDF.num_vars, &mult_flag);
  590.          if(mult_flag)CDFLIST_put_message(screen.MES_vid, MULT_mes,
  591.                 RINGBELL, NORMAL, PAUSE);
  592.          CDFLIST_add_independent(select, &num_select,
  593.             variables, CDF.num_vars);
  594.          }
  595.           CDFLIST_list_data(&screen, &CDF, select, num_select,
  596.             num_filter, data_values, fptr);
  597.           }
  598.        CDFLIST_field_menu(&screen, &field_num);
  599.       }
  600.   }
  601. if(HELP_ptr != NULL)fclose(HELP_ptr);
  602. if(CDF.output == FILEOUT || CDF.output == TERMFILE)fclose(fptr);
  603. if(CDF_is_OPEN)rcode=CDFLIST_close(&CDF);
  604. CDFLIST_close_screen(&screen);
  605. Exit;
  606. }
  607. void header(mnemonic, len, data_type, string_size, header_name)
  608. char        *mnemonic;
  609. long int    len;
  610. long int    data_type;
  611. long int    string_size;
  612. char        header_name[];
  613. {
  614. long int    i;
  615. long int    num_blanks;
  616. long int    field_size;
  617. if(data_type == CDF_EPOCH)
  618.     field_size = SO.EPOCH_output_len[SO.EPOCH_format-1];
  619. else if(data_type == CDF_CHAR || data_type == CDF_UCHAR )
  620.     {
  621.     if(string_size > len)
  622.        field_size = string_size;
  623.     else
  624.        field_size = len;
  625.     }
  626. else
  627.     field_size = 13;
  628. if(len <= field_size)
  629.    {
  630.    num_blanks = (field_size - len) / 2;
  631.    for(i=0; i < num_blanks; i++)
  632.        header_name[i] = ' ';
  633.    for(i=0; i < len; i++)
  634.        header_name[i+num_blanks] = mnemonic[i];
  635.    for(i=num_blanks+len; i < field_size; i++)
  636.        header_name[i] = ' ';
  637.    }
  638. else
  639.    strncpy(header_name, mnemonic, field_size);
  640. header_name[field_size] = '\0';
  641. }
  642. long int print_error(screen, rcode)
  643. struct            GLOBAL_struct    *screen;
  644. CDFstatus    rcode;
  645. {
  646. long int    exit_code;
  647. char    error_mes[CDF_ERRTEXT_LEN];
  648. if(rcode < CDF_WARN)
  649.     exit_code = NOCONTINUE;
  650. else if(rcode < CDF_OK)
  651.     exit_code = CONTINUE;
  652. else if(rcode != CDF_OK)
  653.     exit_code = CONTINUE;
  654. /*
  655. Get and print the error message
  656. */
  657. CDFerror(rcode, error_mes);
  658. CDFLIST_put_message(S.MES_vid, error_mes, RINGBELL, NORMAL, PAUSE);
  659. return(exit_code);
  660. }
  661. CDFstatus CDFLIST_open(CDF, variables, select, VAR_display, SELECT_display,
  662.             data_values)
  663. struct        CDF_struct    *CDF;
  664. struct        variable_struct **variables;
  665. struct        variable_struct **select;
  666. struct        vid_struct    **VAR_display;
  667. struct        vid_struct    **SELECT_display;
  668. union         mixed        **data_values;
  669. {
  670. CDFstatus        rcode;
  671. long int        i;
  672. long int        var_num;
  673. long int        attr_num;
  674. long int        dim_num;
  675. long int        num_true;
  676. long int        num;
  677. void            CDFLIST_valid_minmax();
  678. static char        truncation[] = "...";
  679.  
  680. rcode = CDFopen(C.CDF_name, &C.CDF_id);
  681.  
  682. if(rcode < CDF_OK)return (rcode);
  683. rcode = CDFdoc(C.CDF_id, &C.version, &C.release, C.text);
  684.  
  685. for(i=0; i<CDF_MAX_DIMS; i++)
  686.     C.dim_sizes[i] = FALSE;
  687. rcode = CDFinquire(C.CDF_id, &C.num_dims, C.dim_sizes, &C.encoding,
  688.     &C.majority, &C.max_record_num, &C.num_vars, &C.num_attrs);
  689. if(rcode < CDF_OK)return(rcode);
  690. *variables = (struct variable_struct *)
  691.         malloc(C.num_vars * sizeof(struct variable_struct));
  692. if(*variables == NULL)return(BAD_MALLOC);
  693.  
  694. if(C.version == 1)
  695.    {
  696.    C.encoding = HOST_ENCODING;
  697.    C.majority = COL_MAJOR;
  698.    }
  699. else
  700.    if(C.encoding != NETWORK_ENCODING) C.encoding = HOST_ENCODING;
  701.  
  702. if(C.num_attrs > 0)
  703.    {
  704.    C.attr = (struct attr_struct *)
  705.         malloc(C.num_attrs * sizeof(struct attr_struct));
  706.    if(C.attr == NULL)return(BAD_MALLOC);
  707.    for(attr_num=0; attr_num<C.num_attrs; attr_num++)
  708.        {
  709.        rcode = CDFattrInquire(C.CDF_id, attr_num,
  710.         C.attr[attr_num].attr_mnemonic, &C.attr[attr_num].attr_scope,
  711.          &C.attr[attr_num].max_entry);
  712.        }
  713.    }
  714. /*
  715. Set default for the "**SELECT ALL**" option in variable selection pop-up window
  716. */
  717. C.max_var_len = 14;
  718. for (var_num=0; var_num < C.num_vars; var_num++)
  719.     {
  720.     for(i=0; i<CDF_MAX_DIMS; i++)
  721.     VN.dim_variances[i] = FALSE;
  722.     rcode = CDFvarInquire(C.CDF_id, var_num, VN.var_mnemonic, &VN.data_type,
  723.     &VN.num_bytes, &VN.record_variance, VN.dim_variances);
  724.     if(rcode < CDF_OK)                        /* V1.1 */
  725.        return (rcode);
  726.     else
  727.        {
  728.        VN.var_num = var_num;
  729.        VN.var_mnemonic_len = strlen(VN.var_mnemonic);
  730.        /*
  731.        header(VN.var_mnemonic, VN.var_mnemonic_len, VN.data_type, VN.num_bytes,
  732.           VN.header_name);  */
  733.        if(VN.var_mnemonic_len > C.max_var_len)C.max_var_len=VN.var_mnemonic_len;
  734.        VN.filter = FALSE;
  735.        VN.scalar = SCALAR;
  736.        VN.minmax_flag = NORMAL;
  737.        num_true=0;
  738.        for (i=0; i< C.num_dims; i++)
  739.         {
  740.         if(VN.dim_variances[i] != NOVARY)
  741.            {
  742.            dim_num=i+1;
  743.            num_true++;
  744.            VN.scalar = FALSE;
  745.            }
  746.         }
  747.        if((num_true == 1 && !VN.record_variance) &&
  748.       (VN.data_type != CDF_CHAR && VN.data_type != CDF_UCHAR ))
  749.       {
  750.       VN.dim_num = dim_num;
  751.       VN.num_values=C.dim_sizes[dim_num-1];
  752.       VN.bin_value = (double *) malloc(VN.num_values * sizeof(double));
  753.       VN.char_value = (char *) malloc(VN.num_values*MINMAX_SIZE);
  754.       if(VN.bin_value == NULL || VN.char_value == NULL)
  755.          rcode = BAD_MALLOC;
  756.       else
  757.          rcode = CDFLIST_get_discrete(C.CDF_id, dim_num,
  758.            VN.var_num, VN.data_type,  VN.num_values, VN.bin_value, VN.char_value);
  759.       }
  760.       else
  761.       {
  762.       if(!VN.record_variance && num_true > 1)
  763.           VN.dim_num = MULTIPLE;
  764.       else
  765.           VN.dim_num=0;
  766.       VN.num_values=0;
  767.       }
  768.     if(initialfilters)
  769.        {
  770.        CDFLIST_valid_minmax (C.CDF_id, CDFattrNum(C.CDF_id,"VALIDMIN"), var_num,
  771.     &VN.min, &rcode);
  772.        if(rcode != CDF_OK)VN.minmax_flag = NOTTHERE;
  773.        CDFLIST_valid_minmax (C.CDF_id, CDFattrNum(C.CDF_id,"VALIDMAX"), var_num,
  774.     &VN.max, &rcode);
  775.        if(rcode != CDF_OK)VN.minmax_flag = NOTTHERE;
  776.        rcode = 0;
  777.        }
  778.        /* It is OK if these attributes aren't found */
  779.      }
  780.    }/*var loop*/
  781.  /*
  782. Allocate rest of structures needed based upon number of variables
  783. */
  784.   *select = (struct variable_struct *)
  785.         malloc(C.num_vars * sizeof(struct variable_struct));
  786.   if(*select == NULL)return(BAD_MALLOC);
  787.   if(C.num_vars < 8)
  788.      num = 8;
  789.   else
  790.      num = C.num_vars;
  791.   *VAR_display = (struct vid_struct *)
  792.         malloc(((num+1)*3) * sizeof(struct vid_struct));
  793.    if(*VAR_display == NULL)return(BAD_MALLOC);
  794. /*
  795. allocate the space for a vid structure which contains the variables
  796. extra space for "SELECT ALL" option
  797. */
  798.   *SELECT_display = (struct vid_struct *)
  799.            malloc((C.num_vars+1) * sizeof(struct vid_struct));
  800.   if(*SELECT_display == NULL)return(BAD_MALLOC);
  801.   /*
  802. Load in the variables into the structure
  803. */
  804. for (i=0; i<C.num_vars+1; i++)
  805.      {
  806.     (*SELECT_display)[i].row = 1;
  807.     (*SELECT_display)[i].col = 1;
  808.     if(i == 0)
  809.        strcpy((*SELECT_display)[i].label,"**SELECT ALL**");
  810.     else if((*variables)[i-1].var_mnemonic_len < VARSELECT_COLUMNS)
  811.        strcpy((*SELECT_display)[i].label,(*variables)[i-1].var_mnemonic);
  812.     else
  813.        {
  814.        strncpy((*SELECT_display)[i].label,(*variables)[i-1].var_mnemonic,
  815.            VARSELECT_COLUMNS-3);
  816.        strcat((*SELECT_display)[i].label,truncation);
  817.        }
  818.     (*SELECT_display)[i].field_col = 1;
  819.      }
  820.   *data_values = (union mixed *)
  821.            malloc(C.num_vars * sizeof(union mixed));
  822.   if(*data_values == NULL)return(BAD_MALLOC);
  823.  
  824.   return (rcode);
  825. }
  826.  
  827. void CDFLIST_get_data(CDF, select, num_select, record_num, indices, data_values)
  828. struct CDF_struct      *CDF;
  829. struct variable_struct  select[];
  830. long int        num_select;
  831. long int        record_num;
  832. long int        indices[];
  833. union  mixed        data_values[];
  834.  
  835. {
  836. long int    i;
  837.  
  838. for (i = 0; i < num_select; i++)
  839.      {
  840.      switch (select[i].data_type)
  841.     {
  842.     case CDF_REAL4:
  843.     case CDF_FLOAT:
  844.          select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
  845.         record_num, indices, &data_values[i].r4);
  846.          break;
  847.     case CDF_REAL8:
  848.     case CDF_DOUBLE:
  849.     case CDF_EPOCH:
  850.          select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
  851.         record_num, indices, &data_values[i].r8);
  852.          break;
  853.     case CDF_INT4:
  854.     case CDF_UINT4:
  855.          select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
  856.         record_num, indices, &data_values[i].i4);
  857.          break;
  858.     case CDF_INT2:
  859.     case CDF_UINT2:
  860.          select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
  861.         record_num, indices, &data_values[i].i2);
  862.          break;
  863.     case CDF_BYTE:
  864.     case CDF_INT1:
  865.     case CDF_UINT1:
  866.          select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
  867.         record_num, indices, &data_values[i].byte);
  868.          break;
  869.     case CDF_CHAR:
  870.     case CDF_UCHAR:
  871.          select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
  872.         record_num, indices, data_values[i].string);
  873.          data_values[i].string[select[i].num_bytes] = '\0';
  874.     }
  875.    }
  876. }
  877. CDFstatus CDFLIST_alloc_STRING(select, num_select, data_values)
  878. struct variable_struct  select[];
  879. long int        num_select;
  880. union  mixed        data_values[];
  881. {
  882. long int        i;
  883.  
  884. for (i = 0; i < num_select; i++)
  885.      {
  886.      if(select[i].data_type == CDF_CHAR || select[i].data_type == CDF_UCHAR)
  887. /*
  888. If this is a STRING variable allocate a enough space in the union array
  889. to hold this variable
  890. */
  891.        {
  892.        data_values[i].string = (char *) malloc(select[i].num_bytes+1);
  893.        if(data_values[i].string == NULL)return(BAD_MALLOC);
  894.        }
  895.      }
  896.      return 0;
  897. }
  898. void CDFLIST_free_STRING(select, num_select, data_values)
  899. struct variable_struct  select[];
  900. long int        num_select;
  901. union mixed        data_values[];
  902. {
  903. long int        i;
  904. for(i=0; i<num_select; i++)
  905.     {
  906.     if(select[i].data_type == CDF_CHAR || select[i].data_type == CDF_UCHAR)
  907.        free(data_values[i].string);
  908.     }
  909. }
  910. long int CDFLIST_create_new_CDF(screen, CDF, select, num_select, new_CDF)
  911. struct    GLOBAL_struct    *screen;
  912. struct    CDF_struct    *CDF;
  913. struct variable_struct  select[];
  914. long int        num_select;
  915. struct    CDF_struct    *new_CDF;
  916. {
  917. long int        i;
  918. long int        attr_num;
  919. long int        entry_num;
  920. long int        exit_code;
  921. CDFstatus        rcode;
  922. long int        data_type;
  923. long int        num_elements;
  924. long int        out_attr_num;
  925.  
  926. /*
  927. Create the New CDF
  928. */
  929. rcode = CDFcreate(NC.CDF_name, NC.num_dims, NC.dim_sizes,
  930.            NC.encoding, NC.majority, &NC.CDF_id);
  931. if(rcode != CDF_OK)
  932.   {
  933.   exit_code = print_error(screen, rcode);
  934.   if(exit_code == NOCONTINUE)return (exit_code);
  935.   }
  936. /*
  937. Create the variables
  938. */
  939. for(i=0; i<num_select; i++)
  940.     {
  941.     rcode = CDFvarCreate(NC.CDF_id, select[i].var_mnemonic,
  942.             select[i].data_type, select[i].num_bytes,
  943.             select[i].record_variance, select[i].dim_variances,
  944.             &select[i].out_var_num);
  945.     if(rcode != CDF_OK)
  946.       {
  947.       exit_code = print_error(screen, rcode);
  948.       if(exit_code == NOCONTINUE)return (exit_code);
  949.       }
  950.     }
  951. /*
  952. Create the attributes
  953. */
  954. for (attr_num=0; attr_num<C.num_attrs; attr_num++)
  955.      {
  956.      rcode = CDFattrCreate(NC.CDF_id, C.attr[attr_num].attr_mnemonic,
  957.         C.attr[attr_num].attr_scope, &out_attr_num);
  958.      if(rcode != CDF_OK)
  959.     {
  960.     exit_code = print_error(screen, rcode);
  961.     if(exit_code == NOCONTINUE)return (exit_code);
  962.     }
  963.      }
  964. /*
  965. Insert the global attributes
  966. */
  967. for (attr_num=0; attr_num<C.num_attrs; attr_num++)
  968.      {
  969.      if(C.attr[attr_num].attr_scope == GLOBAL_SCOPE ||
  970.     C.attr[attr_num].attr_scope == GLOBAL_SCOPE_ASSUMED)
  971.     {
  972.     for(entry_num = 0; entry_num <= C.attr[attr_num].max_entry; entry_num++)
  973.         {
  974.         rcode = CDFattrEntryInquire(C.CDF_id, attr_num, entry_num,
  975.                 &data_type, &num_elements);
  976.         if(rcode >= CDF_OK)
  977.            {
  978.            rcode =  put_attr_value(C.CDF_id,  attr_num,  entry_num,
  979.             entry_num, NC.CDF_id, data_type, num_elements);
  980.            if(rcode != CDF_OK)
  981.           {
  982.           exit_code = print_error(screen, rcode);
  983.           if(exit_code == NOCONTINUE)return (exit_code);
  984.           }
  985.         }
  986.         else if(rcode != NO_SUCH_ENTRY)
  987.             {
  988.             exit_code = print_error(screen, rcode);
  989.             if(exit_code == NOCONTINUE)return (exit_code);
  990.             }
  991.         }
  992.     }
  993.      }
  994. /*
  995. Insert the variable attributes
  996. */
  997. for (attr_num=0; attr_num<C.num_attrs; attr_num++)
  998.      {
  999.      for(i = 0; i < num_select; i++)
  1000.      {
  1001.      if(C.attr[attr_num].attr_scope == VARIABLE_SCOPE ||
  1002.         C.attr[attr_num].attr_scope == VARIABLE_SCOPE_ASSUMED)
  1003.         {
  1004.         rcode = CDFattrEntryInquire(C.CDF_id, attr_num, select[i].var_num,
  1005.                 &data_type, &num_elements);
  1006.         if(rcode >= CDF_OK)
  1007.            {
  1008.            rcode = put_attr_value(C.CDF_id, attr_num, select[i].var_num, i,
  1009.             NC.CDF_id, data_type, num_elements);
  1010.            if(rcode != CDF_OK)
  1011.           {
  1012.           exit_code = print_error(screen, rcode);
  1013.           if(exit_code == NOCONTINUE)return (exit_code);
  1014.           }
  1015.            }
  1016.         else if(rcode != NO_SUCH_ENTRY)
  1017.             {
  1018.             exit_code = print_error(screen, rcode);
  1019.             if(exit_code == NOCONTINUE)return (exit_code);
  1020.             }
  1021.         }
  1022.      }
  1023.      }
  1024. return (CDF_OK);
  1025. }
  1026.  
  1027. CDFstatus put_attr_value(in_CDF_id,  attr_num,  entry_num, out_entry_num,
  1028.            out_CDF_id, data_type, num_elements)        /* V1.3 */
  1029. CDFid        in_CDF_id;
  1030. long int    attr_num;
  1031. long int    entry_num;
  1032. long int    out_entry_num;                    /* V1.3 */
  1033. CDFid        out_CDF_id;
  1034. long int    data_type;
  1035. long int    num_elements;
  1036. {
  1037. void         *attr_values;
  1038. CDFstatus    rcode;
  1039.  
  1040. switch(data_type)
  1041.        {
  1042.     case  CDF_REAL4:
  1043.     case  CDF_FLOAT:
  1044.           attr_values =
  1045.         (void *) malloc(num_elements * sizeof(float));
  1046.           if(attr_values == NULL)return(BAD_MALLOC);        /* V1.5 */
  1047.           rcode = CDFattrGet(in_CDF_id, attr_num, entry_num, attr_values);
  1048.           if(rcode >= CDF_OK)                /* V1.1 */
  1049.          {
  1050.          rcode = CDFattrPut(out_CDF_id, attr_num, out_entry_num,
  1051.              data_type, num_elements, attr_values);   /* V1.3 */
  1052.          }
  1053.           break;
  1054.      case CDF_CHAR:
  1055.      case CDF_UCHAR:
  1056.           attr_values = (void *) malloc(num_elements+1);    /* V1.5 */
  1057.           if(attr_values == NULL)return(BAD_MALLOC);
  1058.           rcode = CDFattrGet(in_CDF_id, attr_num, entry_num, attr_values);
  1059.           if(rcode >= CDF_OK)                /* V1.1 */
  1060.          {
  1061.          rcode = CDFattrPut(out_CDF_id, attr_num, out_entry_num,
  1062.              data_type, num_elements, attr_values);     /* V1.3 */
  1063.          }
  1064.           break;
  1065.     case  CDF_REAL8:
  1066.     case  CDF_DOUBLE:
  1067.     case  CDF_EPOCH:
  1068.           attr_values =
  1069.         (void *) malloc(num_elements * sizeof(double));    /* V1.5 */
  1070.           if(attr_values == NULL)return(BAD_MALLOC);
  1071.           rcode = CDFattrGet(in_CDF_id, attr_num, entry_num, attr_values);
  1072.           if(rcode >= CDF_OK)                /* V1.1 */
  1073.          {
  1074.          rcode = CDFattrPut(out_CDF_id, attr_num, out_entry_num,
  1075.              data_type, num_elements, attr_values);    /* V1.3 */
  1076.          }
  1077.           break;
  1078.     case  CDF_INT4:
  1079.     case  CDF_UINT4:
  1080.           attr_values =
  1081.         (void *) malloc(num_elements * sizeof(long int));  /* V1.5 */
  1082.           if(attr_values == NULL)return(BAD_MALLOC);
  1083.           rcode = CDFattrGet(in_CDF_id, attr_num, entry_num, attr_values);
  1084.           if(rcode >= CDF_OK)                /* V1.1 */
  1085.          {
  1086.          rcode = CDFattrPut(out_CDF_id, attr_num, out_entry_num,
  1087.              data_type, num_elements, attr_values);    /* V1.3 */
  1088.          }
  1089.           break;
  1090.     case  CDF_INT2:
  1091.     case  CDF_UINT2:
  1092.           attr_values =
  1093.         (void *) malloc(num_elements * sizeof(short int));  /* V1.5 */
  1094.           if(attr_values == NULL)return(BAD_MALLOC);
  1095.           rcode = CDFattrGet(in_CDF_id, attr_num, entry_num, attr_values);
  1096.           if(rcode >= CDF_OK)                /* V1.1 */
  1097.          {
  1098.          rcode = CDFattrPut(out_CDF_id, attr_num, out_entry_num,
  1099.              data_type, num_elements, attr_values);        /* V1.3 */
  1100.          }
  1101.           break;
  1102.     case  CDF_BYTE:
  1103.     case  CDF_INT1:
  1104.     case  CDF_UINT1:
  1105.           attr_values = (void *) malloc(num_elements);    /* V1.5 */
  1106.           if(attr_values == NULL)return(BAD_MALLOC);
  1107.           rcode = CDFattrGet(in_CDF_id, attr_num, entry_num, attr_values);
  1108.           if(rcode >= CDF_OK)                /* V1.1 */
  1109.          {
  1110.          rcode = CDFattrPut(out_CDF_id, attr_num, out_entry_num,
  1111.              data_type, num_elements, attr_values);       /* V1.3 */
  1112.          }
  1113. }/*end switch*/
  1114. free (attr_values);
  1115. return (rcode);
  1116. }
  1117. void CDFLIST_new_CDF_info(CDF, select, num_select, new_CDF)
  1118. struct    CDF_struct    *CDF;
  1119. struct variable_struct  select[];
  1120. long int        num_select;
  1121. struct    CDF_struct    *new_CDF;
  1122. {
  1123. long int        i,j, ii;
  1124. long int        temp_dim_size;
  1125. long int        vars_per_dim[10];
  1126. long int        num_pass;
  1127. long int        num_vars;
  1128. long int        dim_num;
  1129.  
  1130. strcpy(NC.CDF_name,C.file_name);
  1131. /*
  1132. new number of dimensions = old number of dimensions
  1133. */
  1134. NC.num_dims = C.num_dims;
  1135. /*
  1136. initialize new dim sizes to old dim sizes and also set up the
  1137. input start and stop indices array to complete dimensions
  1138. */
  1139. for (i=0; i<NC.num_dims; i++)
  1140.      NC.dim_sizes[i] = C.dim_sizes[i];
  1141.  
  1142. NC.majority = C.majority;
  1143. NC.encoding = C.encoding;
  1144. /*
  1145. Go thru all dimensions to calculate new dimension sizes
  1146. */
  1147. for(dim_num=1; dim_num <= NC.num_dims; dim_num++)
  1148.     {
  1149.     num_vars = 0;
  1150. /*
  1151. Look for variables that vary with respect to the current dimension
  1152. */
  1153.     for(j=0; j<num_select; j++)
  1154.     {
  1155.     if(select[j].dim_num == dim_num)
  1156.        {
  1157.        vars_per_dim[num_vars] = j;
  1158.        num_vars++;
  1159.        }
  1160.     }
  1161. /*
  1162. Make sure there were variables selected for this dimension
  1163. */
  1164.     if(num_vars > 0)
  1165.        {
  1166. /*
  1167. Loop thru all values in this dimension, all variables in this
  1168. dimension must be checked
  1169. */
  1170.        temp_dim_size = 0;
  1171.        for (j = 0; j < NC.dim_sizes[dim_num-1]; j++)
  1172.         {
  1173.         num_pass=0;
  1174.         for (ii = 0; ii <num_vars; ii++)
  1175.              {
  1176.              i = vars_per_dim[ii];
  1177.              if(!select[i].filter)
  1178.             num_pass++;
  1179.              else
  1180.             {
  1181.             if(select[i].bin_value[j] >= select[i].filter_min &&
  1182.                select[i].bin_value[j] <= select[i].filter_max)
  1183.                num_pass++;
  1184.             }
  1185.              }
  1186. /*
  1187. if the number of variables that passed the test is equal to the number of
  1188. variables selected for this dimension bump the dim size by one
  1189. */
  1190.             if(num_pass == num_vars)temp_dim_size++;
  1191.         }/*loop thru values per dim*/
  1192. /*
  1193. Load in the new size for this dimension
  1194. */
  1195.         NC.dim_sizes[dim_num-1] = temp_dim_size;
  1196.          }/*num_vars>0*/
  1197.     }/*dimension numbers*/
  1198. }
  1199. void CDFLIST_list_data(screen, CDF, select, num_select, num_filter,
  1200.             data_values, fptr)
  1201. struct    GLOBAL_struct    *screen;
  1202. struct    CDF_struct    *CDF;
  1203. struct variable_struct  select[];
  1204. long int        num_select;
  1205. long int        num_filter;
  1206. union mixed        *data_values;
  1207. FILE            *fptr;
  1208. {
  1209. struct    CDF_struct    new_CDF;
  1210. long int        line_cnt;
  1211. long int        line_width;
  1212. long int        num_lines_page;
  1213. long int        cont, cont_file, resp;
  1214. static char        file_mes[]   = "Output to file ";
  1215. static char        tp[] = " taking place...";
  1216. static char        cdf_mes[]   = "Output to CDF ";
  1217. static char        file_done_mes[] = "File Processing complete ";
  1218. #if defined(__MSDOS__)
  1219. static char     scan_mes[] = "Scanning for selected data.  Hit <Q> to interrupt...";
  1220. #else
  1221. static char     scan_mes[] = "Scanning for selected data...";
  1222. #endif
  1223. static char     nodata_mes[] = "No data found in the specified range";
  1224. #ifdef vms
  1225. static char        cont_prompt[] =
  1226. "Hit <CR> to continue listing, any other key + <CR> to end ";
  1227. static char        contfile_prompt[] =
  1228. "Would you like to continue the output to your file (Y/N)";
  1229. #endif
  1230. #if defined(unix) | defined(__MSDOS__)
  1231. static char        cont_prompt[] =
  1232. "Hit <CR> to continue listing, any other key to end ";
  1233. static char        contfile_prompt[] =
  1234. "\nWould you like to continue the output to your file (Y/N)";
  1235. static char        trunc_mes[] =
  1236. "Terminal Output will be truncated at    variables because of line width";
  1237. #endif
  1238. static char        end_prompt[] =
  1239. "END of LISTING, Hit <CR> to continue ";
  1240. char            mes[80];
  1241. long int        valid;
  1242. long int        first;
  1243. long int        first_valid;
  1244. long int        data_found_in_record;
  1245. long int        data_found;
  1246. long int        record_pass;
  1247. long int        i;
  1248. double            fudge_down, fudge_up;
  1249. long int        record_num, out_record_num;
  1250. long int        dim_num;
  1251. long int        x[10],ox[10];
  1252. long int        copy_complete;
  1253. long int        change_output;
  1254. long int        max_terminal;
  1255. long int        rcode;
  1256. long int        exit_code;
  1257. char            num[4];
  1258. char            ch;
  1259. if(C.output != CDFOUT)
  1260.    {
  1261.    for(i=0; i<num_select; i++)
  1262.        {
  1263.        header(select[i].var_mnemonic, select[i].var_mnemonic_len,
  1264.           select[i].data_type, select[i].num_bytes,
  1265.           select[i].header_name);
  1266.        }
  1267.    }
  1268. /*
  1269. if output to a file is specified create a file header
  1270. with the variable information for the listing
  1271. */
  1272. if(C.output == FILEOUT || C.output == TERMFILE)
  1273.    CDFLIST_file_header(CDF, select, num_select, fptr);
  1274. /*
  1275. on UNIX we will only be able to write out 132 chars to screen
  1276. */
  1277. max_terminal = NOTTHERE;
  1278. /*
  1279. Calculate number of lines per page if listing output to terminal
  1280. */
  1281. num_lines_page = 22;
  1282. if(C.output == TERMFILE || C.output == TERMIN)
  1283.    {
  1284.    line_width = 0;
  1285.    for(i=0; i < num_select; i++)
  1286.     {
  1287.     if(select[i].data_type == CDF_EPOCH)
  1288.        line_width = line_width + SO.EPOCH_output_len[SO.EPOCH_format-1];
  1289.     else if(select[i].data_type == CDF_CHAR ||
  1290.         select[i].data_type == CDF_UCHAR)
  1291.         line_width = line_width + select[i].num_bytes;
  1292.     else
  1293.         line_width = line_width + 14;
  1294. #if defined (unix) | defined (__MSDOS__)
  1295.     if((line_width > 132) && (max_terminal == NOTTHERE))
  1296.       {
  1297.         max_terminal = i + 1;
  1298.         sprintf(num, "%2d", max_terminal);
  1299.         strncpy(trunc_mes+37, num, 2);
  1300.         CDFLIST_put_message(S.MES_vid, trunc_mes, RINGBELL, NORMAL, PAUSE);
  1301.       }
  1302. #endif
  1303.     }
  1304.     if(line_width > 78)
  1305.        num_lines_page = 10;
  1306. #if defined (unix) | defined(__MSDOS__)
  1307.     else if(C.output == TERMFILE)
  1308.         num_lines_page = 21;
  1309. #endif
  1310.    }
  1311. /*
  1312. If line_width never got to 132 or VMS, max_terminal and num_select
  1313. will be the same
  1314. */
  1315. if (max_terminal == NOTTHERE)max_terminal = num_select;
  1316.  
  1317. /*
  1318. Fudge factor to insure filtering reliability
  1319. */
  1320. fudge_down = .999999; fudge_up = 1.000001;
  1321. for (i=0; i<num_select; i++)
  1322.   {
  1323.   if(select[i].filter)
  1324.      {
  1325.      if(select[i].data_type != CDF_REAL8 && select[i].data_type != CDF_DOUBLE &&
  1326.     select[i].data_type != CDF_EPOCH)
  1327.             /* V1.6 */
  1328.     {
  1329.     if(select[i].min > 0)
  1330.        select[i].filter_min = fudge_down*select[i].min;
  1331.     else
  1332.        select[i].filter_min = fudge_up*select[i].min;
  1333.  
  1334.     if(select[i].max > 0)
  1335.        select[i].filter_max = fudge_up*select[i].max;
  1336.     else
  1337.        select[i].filter_max = fudge_down*select[i].max;
  1338.     }
  1339.      else
  1340.     {
  1341.        select[i].filter_min = select[i].min;
  1342.        select[i].filter_max = select[i].max;
  1343.     }
  1344.  
  1345.      }
  1346.   }
  1347.  
  1348. mes[0] = '\0';
  1349. /*
  1350. Tell the USER what's going on
  1351. */
  1352. if(C.output == TERMFILE || C.output == TERMIN)
  1353.      CDFLIST_put_message(S.MES_vid, scan_mes, NOBELL, BLINK, NOPAUSE);
  1354. else if(C.output == FILEOUT)
  1355.      {
  1356.      strcat(mes, file_mes); strcat(mes, C.file_name); strcat(mes, tp);
  1357.      CDFLIST_put_message(S.MES_vid, mes, NOBELL, BLINK, NOPAUSE);
  1358.      }
  1359. else
  1360.      {
  1361.      strcat(mes, cdf_mes); strcat(mes, C.file_name); strcat(mes, tp);
  1362.      CDFLIST_put_message(S.MES_vid, mes, NOBELL, BLINK, NOPAUSE);
  1363.      }
  1364. /*
  1365. Generate information about output as though we are always creating
  1366. a new CDF, this will speed processing time
  1367. */
  1368. CDFLIST_new_CDF_info(CDF, select, num_filter, &new_CDF);
  1369. if(C.output == CDFOUT)
  1370.    {
  1371. /*
  1372. Create the NEW CDF
  1373. */
  1374.    rcode = CDFLIST_create_new_CDF(screen, CDF, select, num_select, &new_CDF);
  1375.    if(rcode == NOCONTINUE)return;
  1376.    out_record_num = -1;
  1377.    }
  1378.    first = TRUE; first_valid = TRUE; data_found = FALSE;
  1379.    line_cnt = 0; cont = CONTINUE;
  1380.    change_output = FALSE;
  1381.    fflush(stdin);
  1382.  
  1383. rcode = CDFLIST_alloc_STRING(select, num_select, data_values);
  1384. if(rcode != 0)
  1385.    {
  1386.    exit_code = print_error(screen, rcode);
  1387.    if(exit_code == NOCONTINUE)ExitBAD;
  1388.    }
  1389. /* standby for liftoff */
  1390.  
  1391. for(record_num=0; record_num <= C.max_record_num && cont==CONTINUE; ++record_num)
  1392. {
  1393.     for(dim_num = 0; dim_num < C.num_dims; ++dim_num)
  1394.     {
  1395.     x[dim_num] = 0;
  1396.     ox[dim_num] = 0;
  1397.     }
  1398.     data_found_in_record = FALSE;
  1399.     copy_complete = FALSE;
  1400.     first = TRUE;
  1401.     while (!copy_complete && cont == CONTINUE)
  1402.          {
  1403. /*
  1404. Get the data for the variables
  1405. */
  1406.          CDFLIST_get_data(CDF, select, num_select,
  1407.           record_num, x, data_values);
  1408.          if(first)
  1409.         {
  1410.         CDFLIST_filter(select, num_filter, data_values, SCALAR,
  1411.                    &record_pass);
  1412.         first = FALSE;
  1413.         }
  1414.          if(record_pass)
  1415.         {
  1416.  
  1417. /*
  1418. See if the data falls within the range of the specified filters
  1419. */
  1420.          CDFLIST_filter(select, num_filter, data_values, NORMAL, &valid);
  1421.          if(valid)
  1422.         {
  1423.         if(C.output == CDFOUT)
  1424.            {
  1425.            if(!data_found_in_record)out_record_num++;
  1426.            data_found_in_record = TRUE;
  1427.            CDFLIST_put_CDF(&new_CDF, out_record_num, ox,
  1428.              select, num_select, data_values);
  1429.            data_found = TRUE;
  1430.            }
  1431.         else
  1432.            {
  1433. /*
  1434. Data passes all filters, if this is the first time then save off the
  1435. SMG so data may be listed to the screen
  1436. */
  1437. #ifdef vms
  1438.            if((first_valid) &&
  1439.               (C.output == TERMIN || C.output == TERMFILE))
  1440.            CDFLIST_save_screen(screen);
  1441. #endif
  1442.            data_found = TRUE;
  1443.            line_cnt++;
  1444. /*
  1445. Print a HEADER to the listing
  1446. */
  1447. #if defined(unix) | defined(__MSDOS__)
  1448.            if(line_cnt == 1 && C.output != FILEOUT)
  1449.               unpaste_virtual_display_only(stdscr);
  1450. #endif
  1451.             if(line_cnt == 1)
  1452.                 CDFLIST_print_header(select, num_select, max_terminal,
  1453.                     C.output, fptr, first_valid);
  1454.            first_valid = FALSE;
  1455.                 CDFLIST_print_data(select, data_values, num_select, 
  1456.                  max_terminal, C.output, fptr);
  1457.                 if((line_cnt == num_lines_page) &&
  1458.               (C.output == TERMIN || C.output == TERMFILE))
  1459.                   {
  1460. /*
  1461. End of a full page, see if the USER wishes to continue (TERMINAL output)
  1462. */
  1463.  
  1464.               cont = get_1char(cont_prompt);
  1465.               if(cont != CONTINUE && C.output == TERMFILE)
  1466.              {
  1467. /*
  1468. USER wishes to stop TERMINAL output, if he is using TERMINAL/FILE output
  1469. see if he wishes to continue his output to his FILE
  1470. */
  1471.              resp = FALSE;
  1472.              while(!resp)
  1473.                {
  1474.                cont_file = get_1char(contfile_prompt);
  1475.                if(cont_file == YES || cont_file == yes)
  1476.                   {
  1477.                   C.output = FILEOUT;
  1478. #if defined(unix) | defined(__MSDOS__)
  1479.                   unpaste_virtual_display_only(stdscr);
  1480.                   CDFLIST_draw_main_screen(screen);
  1481. #endif
  1482. #ifdef vms
  1483.                   CDFLIST_restore_screen(screen);
  1484. #endif
  1485.                   mes[0] = '\0';
  1486.                   strcat(mes, file_mes); strcat(mes, C.file_name);
  1487.                   strcat(mes, tp);
  1488.                   CDFLIST_put_message(S.MES_vid, mes, NOBELL,
  1489.                         BLINK, NOPAUSE);
  1490.                   cont = CONTINUE; resp = OK_RESP;
  1491.                   change_output = TRUE;
  1492.                   }
  1493.                 else if(cont_file == NO || cont_file == no)
  1494.                     resp = OK_RESP;    
  1495.                 }
  1496.              }
  1497.                   line_cnt = 0;
  1498.                   } /* line_cnt */
  1499.            }
  1500. /*
  1501. Check output indices to see if all output indices have been filled
  1502. */
  1503.                next_indices(ox, new_CDF.num_dims, new_CDF.dim_sizes, 
  1504.              ©_complete);
  1505.                 } /* valid point */ 
  1506. /*
  1507. Generate next set indices
  1508. */
  1509.         if(cont == CONTINUE && !copy_complete)
  1510.                next_indices(x, C.num_dims, C.dim_sizes, ©_complete);
  1511.         
  1512.           }/* !copy_comple*/
  1513.         else
  1514.         copy_complete = TRUE;
  1515.  
  1516.  
  1517. /*
  1518. Look for user trying to break the search - aw3
  1519. */
  1520.  
  1521. #if defined(__MSDOS__)
  1522.        if (kbhit())  /* abort disp if keypressed */
  1523.        {
  1524.            if ( (ch = getch()) == 0)
  1525.               ch = 0x80 | getch();
  1526.            if ((ch == 'Q') || (ch == 'q'))
  1527.            {
  1528.                 copy_complete = TRUE;
  1529.                 cont = NOCONTINUE;
  1530.            }
  1531.        }
  1532. #endif
  1533.         }/*record_passes*/
  1534.    }/*record_num*/
  1535.  
  1536. CDFLIST_free_STRING(select, num_select, data_values);
  1537.  
  1538. if((C.output == TERMIN || C.output == TERMFILE) &&
  1539.    (cont == CONTINUE && data_found))
  1540.     cont = get_1char(end_prompt);
  1541. else if (C.output == CDFOUT)
  1542.      rcode=CDFLIST_close(&new_CDF);
  1543. if((data_found) &&
  1544.    (C.output == TERMIN || C.output == TERMFILE))
  1545.    {
  1546. /*
  1547. Restore the SMG SCREEN so additional listings may be produced
  1548. */
  1549. #if defined(unix) | defined(__MSDOS__)
  1550.    unpaste_virtual_display_only(stdscr);
  1551.    CDFLIST_draw_main_screen(screen);
  1552. #endif
  1553. #ifdef vms
  1554.    CDFLIST_restore_screen(screen);
  1555. #endif
  1556.    CDFLIST_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS-COL_OFFSET);
  1557.    }
  1558. else if(!data_found)
  1559. /*
  1560. These was no data found in the specified ranges
  1561. */
  1562.     CDFLIST_put_message(S.MES_vid, nodata_mes, RINGBELL, NORMAL, NOPAUSE);
  1563. else
  1564.     CDFLIST_put_message(S.MES_vid, file_done_mes, NOBELL, NORMAL, NOPAUSE);
  1565. first_valid = TRUE;
  1566. first = TRUE;
  1567. if(change_output)C.output = TERMFILE;
  1568. }
  1569. void next_indices(x, num_dims, dim_sizes, copy_complete)
  1570. long int    x[];
  1571. long int    num_dims;
  1572. long int    dim_sizes[];
  1573. long int    *copy_complete;
  1574. {
  1575. long int    cp;
  1576. long int    valid_perm;
  1577. long int    dim_num;
  1578. cp = *copy_complete;
  1579. if(num_dims == 0)
  1580.    cp = TRUE;
  1581. else
  1582.    {
  1583.    valid_perm = FALSE;
  1584.    dim_num = 1;
  1585.    while (!valid_perm && !cp)
  1586.        {
  1587.        if (x[dim_num-1] < (dim_sizes[dim_num-1] - 1)) 
  1588.         {
  1589.        x[dim_num-1] = x[dim_num-1] + 1;
  1590.        valid_perm = TRUE;
  1591.        }
  1592.        else
  1593.         {
  1594.        if (dim_num < num_dims) 
  1595.                 {
  1596.             x[dim_num-1] = 0;
  1597.             dim_num = dim_num + 1;
  1598.            }
  1599.            else
  1600.            cp = TRUE;
  1601.          }    
  1602.        }/*valid_perm*/
  1603.    }
  1604. *copy_complete = cp;
  1605. }
  1606. void CDFLIST_check_filters(select, num_select, variables, num_vars, mult_flag)
  1607. struct variable_struct  select[];
  1608. long int        num_select;
  1609. struct variable_struct  variables[];
  1610. long int        num_vars;
  1611. long int        *mult_flag;
  1612. {
  1613. long int        i,j;
  1614. long int        found;
  1615. *mult_flag = FALSE;
  1616. for (j=0; j<num_select; j++)
  1617.      {
  1618.      if(select[j].dim_num == MULTIPLE)
  1619.     {
  1620.         *mult_flag = TRUE;
  1621.         found = FALSE;
  1622.         for (i=0; i<num_vars && !found; i++)
  1623.              {
  1624.              if(strcmp(select[j].var_mnemonic,variables[i].var_mnemonic)==0)
  1625.         select[j].filter = FALSE;
  1626.                  found = TRUE;
  1627.          }        
  1628.         }
  1629.      }
  1630. for (j=0; j<num_select; j++)
  1631.      {
  1632.      if(select[j].filter && select[j].record_variance == VARY && 
  1633.        !select[j].scalar)select[j].filter = FALSE;
  1634.      }
  1635. }
  1636. void CDFLIST_add_independent(select, num_select, variables, num_vars)
  1637. struct variable_struct  select[];
  1638. long int        *num_select;
  1639. struct variable_struct  variables[];
  1640. long int        num_vars;
  1641. {
  1642. long int        i,j, ii;
  1643. long int        ns;
  1644. long int        found;
  1645. ns = *num_select;
  1646. for (i=0; i<num_vars; i++)
  1647.   {
  1648.   if(!variables[i].record_variance)
  1649.      {
  1650.      found = FALSE;
  1651.      for (j=0; j<ns; j++)
  1652.       {
  1653.       if(strcmp(select[j].var_mnemonic, variables[i].var_mnemonic)==0)
  1654.          found = TRUE;
  1655.       }
  1656.       if(!found)
  1657.          {
  1658.          strcpy(select[*num_select].var_mnemonic,
  1659.             variables[i].var_mnemonic);
  1660.          select[*num_select].var_num = variables[i].var_num;
  1661.          select[*num_select].record_variance =
  1662.           variables[i].record_variance;
  1663.          for (ii=0; ii< 10; ii++)
  1664.           select[*num_select].dim_variances[ii] =
  1665.                variables[i].dim_variances[ii];
  1666.          select[*num_select].num_bytes = variables[i].num_bytes;
  1667.          select[*num_select].num_values= variables[i].num_values;
  1668.          select[*num_select].dim_num = variables[i].dim_num;
  1669.          select[*num_select].bin_value = variables[i].bin_value;
  1670.          select[*num_select].min = variables[i].min;
  1671.          select[*num_select].max = variables[i].max;
  1672.          select[*num_select].data_type = variables[i].data_type;
  1673.          select[*num_select].filter = FALSE;
  1674.          *num_select = *num_select + 1;
  1675.          }
  1676.     }/*RV FALSE*/
  1677.      }/*var loop*/
  1678. }
  1679. void CDFLIST_select_VAR(screen, num_rows, num_cols, display,
  1680.      SELECT_display, possible, num_poss, select, num_select, in_field_num)
  1681. struct            GLOBAL_struct    *screen;
  1682. int            num_rows;
  1683. int            num_cols;
  1684. struct vid_struct       display[];
  1685. struct vid_struct      *SELECT_display;
  1686. struct variable_struct  possible[];
  1687. long int        num_poss;
  1688. struct variable_struct  *select;
  1689. long int        *num_select;
  1690. long int        *in_field_num;
  1691. {
  1692. struct vid_struct      *DIS_display;
  1693. long int        i, n;
  1694. double            min_max;
  1695. long int        var_num, val_num, select_num;
  1696. int            row, col;
  1697. long int        scroll;
  1698. int            tcode;
  1699. long int        col_field, col_paste, dis_rows;
  1700. long int        first_blank;
  1701. int            field_num;
  1702. int            last_error;
  1703. int            len;
  1704. long int        exit_code;
  1705. char            mes[80];
  1706. char            row_data[80];
  1707. char            value[EPOCH_WIDTH];
  1708. char            mnemonic[CDFLIST_MAX_VAR_LENGTH+1];
  1709. char            temp[CDFLIST_MAX_VAR_LENGTH+1];
  1710. char            key_line1[KEY_COLUMNS-COL_OFFSET+1];    /* V1.5 */
  1711. char            key_line2[KEY_COLUMNS-COL_OFFSET+1];    /* V1.5 */
  1712. static int        scolumns[3] = { 6, 26, 52 };
  1713. int            error;
  1714. long int        select_all, start, end;
  1715. long int        erase_mode;
  1716. long int        value_entered;
  1717. long int        start_page; /*jtl*/
  1718. long int        ok;
  1719. Boolean            echeck;
  1720. int             bump;
  1721. int            redraw;
  1722. double            dummy;
  1723. CDFstatus        rcode;
  1724. static char        dup_mes[] = " has already been selected";
  1725. static char        min_max_error[] = "Error detected in MIN_MAX field";
  1726. static char        select_var_mes[] =
  1727. "Press CTL-P to view valid variables and select from pop-up menu";
  1728. static char        select_data_mes[] =
  1729. "Enter MIN/MAX value or press CTL-P to select discrete values from pop-up menu";
  1730. static char        no_discrete_mes[] =
  1731. "Current Variable does not contain only discrete values, manual input required";
  1732. static char        string_mes[] =
  1733. "Variable not available for filtering, please use another variable if possible";
  1734. static char        min_gt_max[] =
  1735. "Minimum value greater than Maximum value";
  1736. static char        EPOCH_format[] =
  1737. "DD-MMM-YYYY HH:MM:SS.MSC";
  1738. static char        EPOCH_error_mes[] =
  1739. "Error detected reading EPOCH";
  1740.  
  1741. var_num = 1;
  1742. tcode = CONTINUE;
  1743. last_error = FALSE;
  1744. col_field = 1;
  1745. redraw = TRUE;
  1746. row = 2;
  1747. read_display(S.VAR_vid, row,  row_data);
  1748. get_field(row_data, 1, 3, mnemonic, &first_blank, &value_entered);
  1749. sscanf(row_data, "%3ld",&select_num);
  1750. start_page = select_num;
  1751. while(tcode != KB_CTRL_F)
  1752.       {
  1753.       key_line1[0] ='\0'; key_line2[0] = '\0';
  1754.       strcat(key_line1,CNTRLM); strcat(key_line1, UP);strcat(key_line1, NEXT);
  1755.       strcat(key_line1, DEL);;
  1756.                                 /* V1.5 */
  1757.       strcat(key_line2,CNTRLW);strcat(key_line2, DOWN);strcat(key_line2,BACK);
  1758.       strcat(key_line2, HLP);
  1759.       CDFLIST_load_keydef(S.KEY_vid, key_line1, key_line2);
  1760. /*
  1761. Calculate which position to be positioned to
  1762. */
  1763.       field_num = select_num * 3 + col_field;
  1764.       col = scolumns[col_field-1];
  1765.       if(redraw)
  1766.      {
  1767.      redraw = FALSE;
  1768.      erase_mode = ERASE;
  1769.      begin_display_update(S.VAR_vid);
  1770.      for(i=0; i<3; i++)
  1771.          {
  1772.          put_chars(S.VAR_vid, display[i].label, 8,
  1773.         display[i].row, display[i].col, erase_mode, NORMAL);
  1774.          erase_mode = NOERASE;
  1775.          }
  1776. #if defined(vms)
  1777.      end_display_update(S.VAR_vid);
  1778. #else
  1779.      end_display_update_nobox(S.VAR_vid);
  1780. #endif
  1781.      }
  1782.       if(col_field == 1)
  1783.      {
  1784. /*
  1785. Select a variable
  1786. */
  1787.      if(!last_error)
  1788.      CDFLIST_put_message(S.MES_vid, select_var_mes, NOBELL, NORMAL, NOPAUSE);
  1789.      last_error = FALSE;
  1790.      set_cursor_abs(S.VAR_vid, row, col);
  1791. /*
  1792. See if the USER wishes to select a variable
  1793. */
  1794. #ifdef   vms
  1795.      read_input(&tcode);
  1796. #endif
  1797. #if defined(unix) | defined(__MSDOS__)
  1798.      read_input(S.VAR_vid, &tcode);
  1799. #endif
  1800.      }
  1801.       else
  1802.      { /* min or max */
  1803. /*
  1804. Minimum or Maximum range input
  1805. first Copy Mnemonic
  1806. */
  1807.      read_display(S.VAR_vid, row,  row_data);
  1808.      get_field(row_data, 6, CDFLIST_MAX_VAR_LENGTH, mnemonic,
  1809.            &first_blank, &value_entered);
  1810.      error = TRUE;
  1811.      while (error)
  1812.            {
  1813.            error = FALSE;
  1814.            set_cursor_abs(S.VAR_vid, row, col);
  1815.            read_display(S.VAR_vid, row,  row_data);
  1816. /*
  1817. Copy Mnemonic
  1818. */
  1819.            get_field(row_data, 6, CDFLIST_MAX_VAR_LENGTH, mnemonic,
  1820.            &first_blank, &value_entered);
  1821. /*
  1822. Copy Minimum or Maximum value so it may be edited
  1823. */
  1824.            var_num = get_var_num(possible, mnemonic, num_poss);
  1825.            if(var_num == NOTTHERE)
  1826.           len = MINMAX_SIZE;
  1827.            else if(possible[var_num].data_type != CDF_EPOCH)
  1828.           len = MINMAX_SIZE;
  1829.            else
  1830.           {
  1831.           len = EPOCH_WIDTH;
  1832.           put_chars(S.VAR_vid, EPOCH_format, EPOCH_WIDTH,
  1833.           display[col_field-1].row, display[col_field-1].col,
  1834.           NOERASE, NORMAL);
  1835.           redraw = TRUE;
  1836.           }
  1837.            if(!last_error)
  1838.           CDFLIST_put_message(S.MES_vid, select_data_mes, NOBELL,
  1839.           NORMAL, NOPAUSE);
  1840.            get_field(row_data, col, len, value,
  1841.            &first_blank, &value_entered);
  1842.            input_field(S.VAR_vid, value,
  1843.            row, col, len-1, &tcode);
  1844. #if !defined(__MSDOS__)
  1845.            change_rendition(S.VAR_vid,row,col,1,len,NORMAL);
  1846. #endif
  1847.            if(possible[var_num].data_type != CDF_EPOCH)
  1848.           {
  1849.           n = sscanf(value,"%lf",&min_max);
  1850.           if(n == MIN_MAX_ERROR)
  1851.              {
  1852.              CDFLIST_put_message(S.MES_vid, min_max_error, RINGBELL,
  1853.                     BLINK, PAUSE);
  1854.              error = TRUE;
  1855.              }
  1856.           else
  1857.              {
  1858.              strcpy(display[field_num-1].label, value);
  1859.              if(error)
  1860.              CDFLIST_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS);
  1861.              }
  1862.           } /* normal min or max */
  1863.            else
  1864.           { /* EPOCH min or MAX */
  1865.           echeck = check_epoch(value, &dummy);
  1866.           if(!echeck)
  1867.              {
  1868.              CDFLIST_put_message(S.MES_vid, EPOCH_error_mes, RINGBELL,
  1869.                     BLINK, PAUSE);
  1870.              error = TRUE;
  1871.              }
  1872.               else
  1873.              {
  1874.              CDFLIST_put_select_row(S.VAR_vid, display, row, field_num-1,
  1875.              value, EPOCH_WIDTH, NORMAL);
  1876.              strcpy(display[field_num-1].label, value);
  1877.                  if(error)
  1878.              CDFLIST_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS);
  1879.              }
  1880.           } /* end EPOCH min or max */
  1881.            } /* read in value */
  1882.      }/* min or max end */
  1883.       switch (tcode)
  1884.           {
  1885.           case KB_DOWNARROW:
  1886.            row++; select_num++;
  1887.            if(select_num > num_poss)select_num = 1;
  1888.            if(row > 9)
  1889.           {
  1890.               if(num_poss > 8)
  1891.              {
  1892.              row = 9;
  1893.              start_page++;
  1894.              if(start_page > num_poss)start_page = 1;
  1895.              load_vars(S.VAR_vid, display, start_page, num_poss);
  1896.              }
  1897.           else
  1898.              {
  1899.              row = 2;
  1900.              select_num = 1;
  1901.              start_page = 1;
  1902.              }
  1903.           }
  1904.            break;
  1905.       case KB_UPARROW:
  1906.            row--; select_num--;
  1907.            if(select_num < 1)select_num = num_poss;
  1908.            if(row < 2)
  1909.           {
  1910.               if(num_poss > 8)
  1911.              {
  1912.              row = 2;
  1913.              start_page--;
  1914.              if(start_page < 1)start_page = num_poss;
  1915.              load_vars(S.VAR_vid, display, start_page, num_poss);
  1916.              }
  1917.           else
  1918.              {
  1919.              row = 9;
  1920.              select_num = 8;
  1921.              start_page = 1;
  1922.              }
  1923.           }
  1924.            break;
  1925.       case KB_RIGHTARROW:
  1926.       case KB_RETURN:
  1927.       case KB_PAD_ENTER:
  1928.            col_field++;
  1929.            scroll = FALSE;
  1930.            next_field(&col_field, &select_num, &start_page, &row, &scroll,
  1931.                 num_poss);
  1932.            if(scroll)
  1933.            load_vars(S.VAR_vid, display, start_page, num_poss);
  1934.            break;
  1935.       case KB_LEFTARROW:
  1936.       case KB_BACKFIELD:
  1937.            col_field--;
  1938.            scroll = FALSE;
  1939.            next_field(&col_field, &select_num, &start_page, &row, &scroll,
  1940.                 num_poss);
  1941.            if(scroll)
  1942.           load_vars(S.VAR_vid, display, start_page, num_poss);
  1943.            break;
  1944.       case KBF_POPUP:
  1945.            if(col_field == 1)
  1946.           {
  1947. /*
  1948. Select variables from a POP-UP
  1949. */
  1950.           CDFLIST_menu_keydef(screen);
  1951.           CDFLIST_select_menu_item(S.VARSELECT_vid,
  1952.           S.MES_vid,&var_num, SELECT_display, num_poss+1, num_rows,
  1953.           num_cols, VARSELECT_ROW_PASTE, VARSELECT_COL_PASTE,
  1954.           MENU, &tcode);
  1955.              if(tcode == KB_CTRL_F)
  1956.             {
  1957.             rcode = CDFLIST_read_VAR(display, possible,
  1958.             num_poss, select, num_select);
  1959.             if(rcode == 0)
  1960.                CDFLIST_field_menu(screen, in_field_num);
  1961.             else
  1962.                {
  1963.                CDFLIST_put_message(S.MES_vid, min_gt_max, RINGBELL,
  1964.                     NORMAL, NOPAUSE);
  1965.                last_error = TRUE;
  1966.                tcode = CONTINUE;
  1967.                }
  1968.             }
  1969.           else if(tcode == KB_RETURN)
  1970.               {
  1971. /*
  1972. USER selected a variable
  1973. */
  1974.              if(var_num == SELECT_ALL)
  1975.                 {
  1976. /*
  1977. "SELECT ALL" option: loop thru all variables
  1978. */
  1979.                 start = 1;
  1980.                 end = num_poss;
  1981.                 select_num = 1;
  1982.                 start_page = 1;
  1983.                 select_all = TRUE;
  1984.                 row = 2;
  1985.                 init_var_display(display, num_poss);
  1986.                 load_vid(S.VAR_vid, display, 0,
  1987.                 VAR_NUM_ELEMENTS, VAR_label);
  1988.                 }
  1989.               else
  1990.                 {
  1991. /*
  1992. Selecting one variable
  1993. */
  1994.                 start = var_num - 1;
  1995.                 end = var_num - 1;
  1996.                 select_all = FALSE;
  1997.                 }
  1998.               for(var_num = start; var_num <= end; var_num++)
  1999.               {
  2000.               field_num = select_num * 3 + col_field;
  2001.               len = strlen(SELECT_display[var_num].label);
  2002.               if(len > CDFLIST_MAX_VAR_LENGTH)len=CDFLIST_MAX_VAR_LENGTH;
  2003.               strncpy(temp, SELECT_display[var_num].label, len);
  2004.               temp[len] = '\0';
  2005.               if(!select_all)
  2006. /*
  2007. Check if current variable has been selected
  2008. */
  2009.                  ok = check_var(display, temp, num_poss);
  2010.               else
  2011.                  ok = TRUE;
  2012.               if(!ok)
  2013.                  {
  2014.                  strcpy(mes,temp);
  2015.                  strcat(mes,dup_mes);
  2016.                  CDFLIST_put_message(S.MES_vid, mes, RINGBELL,
  2017.                     NORMAL, NOPAUSE);
  2018.                  last_error = TRUE;
  2019.                  }
  2020.               else
  2021.                  {
  2022.                  erase_display(S.VAR_vid, row, col, row,
  2023.                 VAR_COLUMNS-COL_OFFSET);
  2024. /*
  2025. Display selected variable
  2026. */
  2027.                  CDFLIST_put_select_row(S.VAR_vid, display, row,
  2028.                  field_num-1, temp, len, REVERSE);
  2029. /*
  2030. Save selected variable
  2031. */
  2032.                  strcpy(display[field_num-1].label+
  2033.                    (display[field_num-1].field_col-1), temp);
  2034.                  if(initialfilters)
  2035. /*
  2036. Display VALIDMIN & VALIDMAX if system uses NSSDC_STANDARD
  2037. */
  2038.                 {
  2039.                 if(possible[var_num-1].data_type == CDF_EPOCH)
  2040.                    {
  2041.                    if(possible[var_num-1].minmax_flag !=
  2042.                       NOTTHERE)
  2043.                       {
  2044. /*
  2045. Display EPOCH time
  2046. */
  2047.                       CDFLIST_put_TIME(S.VAR_vid, display, row,
  2048.                        field_num-1+1, possible[var_num-1].min);
  2049.                       CDFLIST_put_TIME(S.VAR_vid, display, row,
  2050.                        field_num-1+2, possible[var_num-1].max);
  2051.                       }
  2052.                    }
  2053.                 else
  2054.                    {
  2055.                    if(possible[var_num-1].data_type !=
  2056.                                 CDF_CHAR
  2057.                    && possible[var_num-1].data_type !=
  2058.                                 CDF_UCHAR)
  2059.                       {
  2060.                       if(possible[var_num-1].minmax_flag !=
  2061.                      NOTTHERE)
  2062.                      {
  2063.                      CDFLIST_put_value(S.VAR_vid, display,
  2064.                      row, field_num-1+1,
  2065.                      possible[var_num-1].min);
  2066.                      CDFLIST_put_value(S.VAR_vid, display,
  2067.                      row, field_num-1+2,
  2068.                      possible[var_num-1].max);
  2069.                      } /* VALIDMIN or VALIDMAX not found */
  2070.                       } /* datatype not CDF_CHAR */
  2071.                    } /* Not EPOCH data type */
  2072.                 } /* is NSSDC_STANDARD */
  2073.                  if(!select_all)
  2074.                 col_field++;
  2075.                  else
  2076.                 col_field = 4;
  2077.                  scroll = FALSE;
  2078.                  next_field(&col_field, &select_num,
  2079.                     &start_page, &row, &scroll, num_poss);
  2080.                  if(scroll)
  2081.                     load_vars(S.VAR_vid, display, start_page, num_poss);
  2082.                  }
  2083.               }/*select loop*/
  2084. /*
  2085. Now scroll back up to the top
  2086. */
  2087.               if(select_all && num_poss > 8)
  2088.                 {
  2089.                 for(i=0; i<7; i++)
  2090.                 {
  2091.                 start_page++;
  2092.                 load_vars(S.VAR_vid, display, start_page,
  2093.                 num_poss);
  2094.                 }
  2095.                 row = 2;
  2096.                 start_page = 1;
  2097.                 select_num = 1;
  2098.                 }
  2099.             }/*KB_RETURN*/
  2100.           }
  2101.            else
  2102.           {
  2103.           bump = TRUE;
  2104. /*
  2105. USER wishes to select from a POP-UP menu of values for a variable
  2106. EPOCH does not have a discrete set of values
  2107. Find the variable that the USER wishes to select from
  2108. */
  2109.           var_num = get_var_num(possible, mnemonic, num_poss);
  2110.           if(var_num != NOTTHERE)
  2111.              {
  2112.              if(possible[var_num].num_values == 0)
  2113.             {
  2114.             bump = FALSE;
  2115.             if(possible[var_num].data_type != CDF_CHAR &&
  2116.                possible[var_num].data_type != CDF_UCHAR)
  2117.                CDFLIST_put_message(S.MES_vid, no_discrete_mes,
  2118.                 RINGBELL, NORMAL, PAUSE);
  2119.             else
  2120.                CDFLIST_put_message(S.MES_vid, string_mes, RINGBELL,
  2121.                               NORMAL, PAUSE);
  2122.             }
  2123.              else
  2124.             {
  2125.             DIS_display = (struct vid_struct *)
  2126.                 malloc(possible[var_num].num_values *
  2127.                 sizeof(struct vid_struct));
  2128.             if(DIS_display == NULL)
  2129.                {
  2130.                exit_code = print_error(screen, BAD_MALLOC);
  2131.                if(exit_code == NOCONTINUE)ExitBAD;
  2132.                }
  2133. /*
  2134. Load in the values in the virtual display
  2135. */
  2136.                CDFLIST_load_discrete(possible[var_num].char_value,
  2137.              possible[var_num].num_values, col_field,
  2138.              DIS_display, &dis_rows, &col_paste);
  2139. #ifdef vms
  2140.                change_virtual_display(dis_rows, DIS_COLUMNS,
  2141.             S.DIS_vid, BORDER, BOLD);
  2142. #endif
  2143. #if defined(unix) | defined(__MSDOS__)
  2144.                change_virtual_display(dis_rows, DIS_COLUMNS,
  2145.             &S.DIS_vid, BORDER, BOLD);
  2146. #endif
  2147.  
  2148. /*
  2149. Select desired value
  2150. */
  2151.                CDFLIST_menu_keydef(screen);
  2152.                CDFLIST_select_menu_item(S.DIS_vid,
  2153.             S.MES_vid, &val_num, DIS_display,
  2154.             possible[var_num].num_values,  dis_rows, DIS_COLUMNS,
  2155.             DIS_ROW_PASTE, col_paste, MENU, &tcode);
  2156.             if(tcode == KB_CTRL_F)
  2157.               {
  2158.               rcode = CDFLIST_read_VAR(display, possible,
  2159.                   num_poss, select, num_select);
  2160.               if(rcode == 0)
  2161.                CDFLIST_field_menu(screen, in_field_num);
  2162.               else
  2163.                  {
  2164.                  CDFLIST_put_message(S.MES_vid, min_gt_max, RINGBELL,
  2165.                     NORMAL, NOPAUSE);
  2166.                  last_error = TRUE;
  2167.                  tcode = CONTINUE;
  2168.                  }
  2169.               }
  2170.             else if(tcode != QUIT)
  2171.                  {
  2172.                  CDFLIST_put_select_row(S.VAR_vid, display, row,
  2173.                  field_num-1, DIS_display[val_num-1].label,
  2174.                  MINMAX_SIZE-1, NORMAL);
  2175.                  strcpy(display[field_num-1].label,
  2176.                    DIS_display[val_num-1].label);
  2177.                  }
  2178.                 free(DIS_display);
  2179.             }
  2180.              }/*var_num there or not*/
  2181.              if(bump)
  2182.             {
  2183.             col_field++;
  2184.             scroll = FALSE;
  2185.             next_field(&col_field, &select_num,
  2186.                 &start_page, &row, &scroll, num_poss);
  2187.             if(scroll)
  2188.                load_vars(S.VAR_vid, display, start_page,
  2189.                     num_poss);
  2190.             }
  2191.           }
  2192.            break;
  2193.       case KB_CTRL_F:
  2194.            rcode = CDFLIST_read_VAR(display, possible, num_poss,
  2195.            select, num_select);
  2196.            if(rcode == 0)
  2197.           CDFLIST_field_menu(screen, in_field_num);
  2198.            else
  2199.           {
  2200.           CDFLIST_put_message(S.MES_vid, min_gt_max, RINGBELL,
  2201.                     NORMAL, NOPAUSE);
  2202.           last_error = TRUE;
  2203.           tcode = CONTINUE;
  2204.           }
  2205.            break;
  2206.       case KB_REDRAW:
  2207.            repaint_screen();
  2208.            break;
  2209.       case KB_DELETE:
  2210.            erase_display(S.VAR_vid, row, col, row, VAR_COLUMNS-COL_OFFSET);
  2211. /*
  2212. Delete current variable
  2213. */
  2214.            display[field_num-1].label[display[field_num-1].field_col-1]='\0';
  2215.            display[field_num-1+1].label[0]='\0';
  2216.            display[field_num-1+2].label[0]='\0';
  2217.            break;
  2218.       }
  2219.       }
  2220. }
  2221.  
  2222.  
  2223.  
  2224.  
  2225.  
  2226.  
  2227.